﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Entity;

namespace IRepository
{
    public interface IInventoryRepository
    {
        // 库存主表操作
        Task<List<InventoryEntity>> GetByWarehouseAndProductAsync(int warehouseId, string productCode);
        Task<List<InventoryEntity>> GetByWarehouseAndProductAsync(int warehouseId, string productCode, IDbTransaction transaction);
        Task UpdateAsync(InventoryEntity entity);
        Task UpdateAsync(InventoryEntity entity, IDbTransaction transaction);
        Task AddAsync(InventoryEntity entity);
        Task AddAsync(InventoryEntity entity, IDbTransaction transaction);
        Task LockWarehouseAsync(string warehouseName);

        // 盘点明细操作
        Task AddInventoryDetailsAsync(int listId, List<InventoryDetailsEntity> details);
        Task UpdateInventoryDetailAsync(InventoryDetailsEntity detail);
        Task<List<InventoryDetailsEntity>> GetInventoryDetailsByListIdAsync(int listId);
        Task DeleteInventoryDetailAsync(int detailId);

        /// <summary>
        /// 检查仓库是否锁定
        /// </summary>
        Task<bool> CheckWarehouseLockAsync(string warehouseName);

        /// <summary>
        /// 批量查询产品库存（支持仓库、库位筛选）
        /// </summary>
        Task<Dictionary<string, int>> GetBatchStockByProductCodesAsync(
            List<string> productCodes,
            int? warehouseId = null,
            string location = null);

        /// <summary>
        /// 按货品编码+仓库ID查询库存（含事务）
        /// </summary>
        Task<InventoryEntity> GetByProductCodeAndWarehouseIdAsync(string productCode, int warehouseId, IDbTransaction transaction);

        /// <summary>
        /// 更新库存数量（含事务）
        /// </summary>
        Task UpdateInventoryAsync(InventoryEntity entity, IDbTransaction transaction);

        /// <summary>
        /// 新增库存记录（无库存时，含事务）
        /// </summary>
        Task AddInventoryAsync(InventoryEntity entity, IDbTransaction transaction);
    }
}